package org.jeecg.modules.demo.moneylevelnewuser.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.demo.moenydata.uitils.GamesEnum;
import org.jeecg.modules.demo.moneylevel.entity.MoneyLevelData;
import org.jeecg.modules.demo.moneylevelnewuser.service.INewUserMoneyLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author yw
 * @Date 2021/3/17 13:55
 */
@Api(tags="新用户提现档次分布")
@RestController
@RequestMapping("/newuser/money/level")
@Slf4j
public class NewUserMoneyLevelController {

    @Autowired
    INewUserMoneyLevelService newUserMoneyLevelService;

    @AutoLog(value = "新用户提现档次分布-分页列表查询")
    @ApiOperation(value="新用户提现档次分布-分页列表查询", notes="新用户提现档次分布-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(MoneyLevelData moneyLevelData,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   @RequestParam(name = "num",required = false) String num,
                                   HttpServletRequest req) {
        String tbName= GamesEnum.getTableName(num);
        if(tbName.equals("erro")){
            return Result.error("没有对应该参数的库表!");
        }
        moneyLevelData.setTableName1(tbName+"moneydata");
        moneyLevelData.setTableName2(tbName+"eventdata");
        Map<String, String[]> parameterMap=req.getParameterMap();
        //循环遍历查询条件
		/*for(String key:parameterMap.keySet()){
			String value = parameterMap.get(key)[0].toString();//
			System.out.println("key:"+key+" vlaue:"+value);
		}*/
        moneyLevelData.setPageNo(pageNo*pageSize-pageSize);
        moneyLevelData.setPageSize(pageNo*pageSize);
        if(parameterMap.containsKey("system")){
            moneyLevelData.setSystem(parameterMap.get("system")[0].toString());
        }
        if(parameterMap.containsKey("begintime")){
            moneyLevelData.setBegintime(parameterMap.get("begintime")[0].toString());
        }
        if(parameterMap.containsKey("endtime")){
            moneyLevelData.setEndtime(parameterMap.get("endtime")[0].toString());
        }
        Integer total=newUserMoneyLevelService.getDataCount(moneyLevelData);
        if(total==0){
            return Result.error("无数据");
        }
        List<MoneyLevelData> pageList=newUserMoneyLevelService.getDataList(moneyLevelData);
        List<MoneyLevelData> levelList=newUserMoneyLevelService.getDataLevelList(moneyLevelData);
        for (int i =0;i<pageList.size();i++){
            pageList.get(i).setMoney1(levelList.get(i).getMoney1());
            pageList.get(i).setMoney2(levelList.get(i).getMoney2());
            pageList.get(i).setMoney3(levelList.get(i).getMoney3());
            pageList.get(i).setMoney4(levelList.get(i).getMoney4());
            pageList.get(i).setMoney5(levelList.get(i).getMoney5());
            pageList.get(i).setMoney6(levelList.get(i).getMoney6());
            pageList.get(i).setMoney7(levelList.get(i).getMoney7());
            pageList.get(i).setMoney8(levelList.get(i).getMoney8());
            pageList.get(i).setMoney9(levelList.get(i).getMoney9());
        }
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("records",pageList);
        map.put("total",total);
        return Result.OK(map);
    }
}
